I currently have a bash script which loops the results of the find command;
Code:
for k in `find $assets -iname $j -type f`
but would like to allow users to set a no-recursive parameter which will add the -maxdepth parameter to the above find command;
Code:
...
[ "$recurse" == "0" ] && maxdepth='-maxdepth 1'
...
for k in `find $assets $maxdepth -iname $j -type f`
Unfortunately, the above yields the error;
find: invalid predicate `-maxdepth=1'
However, setting two variables;
Code:
...
if [ "$recurse" == "0" ]
then
maxdepth_param='-maxdepth'
maxdepth_val='1'
fi
...
for k in `find $assets $maxdepth_param $maxdepth_val -iname $j -type f`
works perfectly but seems extraneous.
Is this the only way to accomplish this or is there a cleaner solution.
Any help much appreciated.